<template>
  <div>
    <el-container>

      <el-header class="homeHeader">
        <div class="title">云E办系统</div>
        <el-dropdown class="userInfo" @command="handleHeader">
          <span class="el-dropdown-link">
            欢迎您，{{ user.name }}
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
            <el-dropdown-item command="setting">设置</el-dropdown-item>
            <el-dropdown-item command="logout">注销登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>

      <el-container>

        <el-aside width="200px">
          <!-- 启用路由模式 -->
          <el-menu router unique-opened>
            <el-submenu :index="index+''" v-for="(item, index) in routes" :key="index" v-if="!item.hidden">
              <template slot="title">
                <i :class="item.iconCls" style="color: #1accff;margin-right: 5px"></i>
                <span>{{ item.name }}</span>
              </template>
              <el-menu-item :index="children.path" v-for="(children, indexJ) in item.children">
                <span>{{ children.name }}</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>

        <el-main>
          <router-view/>
        </el-main>

      </el-container>
      
    </el-container>
  </div>
</template>

<script>

import el from "element-ui/src/locale/lang/el";
import {Message} from "element-ui";

export default {
  name: "Home",
  data() {
    return {
      user: JSON.parse(window.sessionStorage.getItem("user"))
    }
  },
  computed: {
    routes() {
      return this.$store.state.routes;
    },
  },
  methods: {
    handleHeader(command) {
      if (command === 'logout') {
        //注销登录
        this.postRequest('/logout');
        window.sessionStorage.removeItem("tokenStr");
        window.sessionStorage.removeItem("user");
        this.$router.replace("/")
      }else if (command === 'userinfo') {
        Message.success('个人中心')
      }else if (command === 'setting') {
        Message.success('设置')
      }
    }
  }
}
</script>

<style scoped>
.homeHeader {
  background: #409eff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  box-sizing: border-box;
}

.homeHeader .title {
  font-size: 30px;
  font-family: 华文楷体;
  color: white;
}

.homeHeader .userInfo {
  cursor: pointer;
}

.homeHeader .el-dropdown-link {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  margin-left: 8px;
  font-size: 20px;
}
</style>